<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Zeta-Daryll
 * Date: 6/17/14
 * Time: 12:09 PM
 * To change this templates use File | Settings | File Templates.
 */
class AdminModel extends CI_Model {

    public function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database();
    }
    public function is_valid(){
        $username = $this->input->post('userid');
        $password = $this->input->post('password');
        $condition = array(
            'u_username'=>$username,
            'u_password'=>base64_encode($password)
        );
        $this->db->from('user');
        $this->db->where($condition);
        $query = $this->db->get();
        return $query->row_array();
    }
    function GetAlldByUsername($user){
        $query = $this->db->query("SELECT * FROM user WHERE u_username = '$user'");
        if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

    function GetInforUser(){
        $query = $this->db->get('user');
        return $query->result_array();
    }
    function CheckAll($ivar,$itest){
        if($itest == "user"){
            $this->db->from('user');
            $this->db->where('u_username',$ivar);
            $query = $this->db->get();
            return $query->num_rows();
        }else{
            $this->db->from('user');
            $this->db->where('u_email',$ivar);
            $query = $this->db->get();
            return $query->num_rows();
        }
        
    }
    function Add_User($data){
            $this->db->insert('user',$data);
    }
}
